package game.shader;

import VectorMath.vec2;
import VectorMath.vec4;
import glsl.OpenFLGraphicsShader;
import VectorMath.fract;
import glsl.GLSL.texture2D;

/**
 * 重复纹理着色器
 */
@:build(game.macro.ShaderInstanceMacro.build())
class RepeatTextureShader extends OpenFLGraphicsShader {
	@:precision("highp float")
	override function fragment() {
		var sizeUv:Vec2 = vec2(40960 / 512);
		var pos:Vec2 = this.gl_openfl_TextureCoordv * sizeUv;
		pos.x = fract(pos.x * 0.5);
		pos.y = fract(pos.y * 0.5);
		var color:Vec4 = texture2D(gl_bitmap, pos);
		this.gl_FragColor = color;
		// var offestCoord:Vec2 = offestv / worldSize;
		// var sizeUv:Vec2 = sizev * scalev / worldSize;
		// var pos:Vec2 = this.gl_openfl_TextureCoordv * sizeUv + offestCoord;
		// pos.x = fract(pos.x / scaleFactor);
		// pos.y = fract(pos.y / scaleFactor);
		// this.gl_FragColor = texture2D(maskBitmapData, pos) * color.a;
	}
}
